/**
 * 柱状图层
 */
define([
    'require',
    './init'
], function(require, init) {
    'use strict';
    var columns = new Array();
    (function Column(){
        var viewer = init.viewer;
        
        viewer.clock.shouldAnimate = false;
        viewer._cesiumWidget._creditContainer.style.display = "none";
        
        var url = '/src/data/population.json';
        var heightScale = 10000000;
    
        Cesium.Resource.fetchJson(url).then(function(data){
            // 解析JSON数据
            // 循环遍历每一组
            for(var k = 0; k < data.length; ++k){
                var series = data[k];
                var seriesName = series[0];     // 名称
                var coordinates = series[1];    // 坐标
    
                // 遍历坐标
                for(var i = 0; i < coordinates.length; i += 3){
                    var latitude = coordinates[i];      // 维度
                    var longitude = coordinates[i+1];   // 经度
                    var height = coordinates[i+2];      // 高度
    
                    var color = Cesium.Color.fromHsl((0.6 - (height * 0.5)), 1.0, 0.5); // 颜色
                    var surfacePosition = Cesium.Cartesian3.fromDegrees(longitude, latitude, 0);
                    var heightPosition = Cesium.Cartesian3.fromDegrees(longitude, latitude, height * heightScale);
    
                    var polyline = new Cesium.PolylineGraphics();
                    polyline.material = new Cesium.ColorMaterialProperty(color);
                    polyline.width = new Cesium.ConstantProperty(2);
                    polyline.followSurface = new Cesium.ConstantProperty(false);
                    polyline.positions = new Cesium.ConstantProperty([surfacePosition, heightPosition]);
                
                    var entity = new Cesium.Entity({
                        id : seriesName + ' index ' + i.toString(),
                        show : true,
                        polyline : polyline,
                        seriesName : seriesName 
                    });
    
                    columns.push(entity);
                }
            }
        })
    })();
    return columns;
});